package com.upay.android.client.handler;

import java.util.List;

import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.upay.android.client.R;
import com.upay.android.client.activity.AbstractUPayActivity;
import com.upay.android.client.adapter.WeightedUserArrayAdapter;
import com.upay.domain.account.WeightedPaymentUser;
import com.upay.domain.response.ResponseEnvelope;

public class GroupWeightedUsersCallbackHandler extends AbstractCallbackHandler<List<WeightedPaymentUser>> {
	
	/* ---- Constants ---- */
	
	/* ---- Instance Variables ---- */
	private List<WeightedPaymentUser> users = null;
	
	/* ---- Constructors ---- */

	public GroupWeightedUsersCallbackHandler(AbstractUPayActivity context) {
		this.context = context;
	}
	
	/* ---- Business Methods ---- */
	

	@Override
	public void handleResponse(ResponseEnvelope<List<WeightedPaymentUser>> response) {
		users = response.getResponseBody().getResponseObject();
		ArrayAdapter<WeightedPaymentUser> adapter = new WeightedUserArrayAdapter(getContext(), users);
		ListView userList = (ListView)getContext().findViewById(R.id.groupweighteduserlist);
		userList.setAdapter(adapter);
		userList.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
				int position, long id) {
				Toast.makeText(context.getApplicationContext(),
					"Click ListItem Number " + position, Toast.LENGTH_LONG)
					.show();
				
//				Intent intent = new Intent(getContext(), SelectedGroupActivity.class);
//				getContext().startActivity(intent);
			}
		});
	}

	@Override
	public void handleValidationException(ResponseEnvelope<List<WeightedPaymentUser>> response) {
		// Handle the exception for not providing correct userid and token;
	}

}
